﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text;
using System.Data;

namespace HZ.Supervise.Web
{
    public partial class msgAlert : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GetAlertContent();
        }

        /// <summary>
        /// 获取提醒内容
        /// </summary>
        /// <returns></returns>
        protected string GetAlertContent()
        {

            StringBuilder strMessage = new StringBuilder();
            int totalrecord = 0;

            Model.Message mess = new HZ.Supervise.Model.Message();
            mess.UserId = CurrentAccount.UserID;

            HZ.Supervise.IBLL.IBLL_MessageTypeDetail ibllMess = new HZ.Supervise.BLL.BLL_MessageTypeDetail();
            DataTable dt = new DataTable();
            dt = ibllMess.GetMessageForWindow();//取得消息数据源

            //取得规则类别
            DataTable dtMessType = new DataTable();
            dtMessType = ibllMess.GetMessageType();//升序

            for (int i = 0; i < dtMessType.Rows.Count; i++)
            {
                string strRows = "rows" + i.ToString();
                DataRow[] Rows = dt.Select("TypeId=" + dtMessType.Rows[i]["TypeId"] + " and UserId='" + mess.UserId + "'");
                int typeId = int.Parse(dtMessType.Rows[i]["typeId"].ToString());
                if (Rows.Length > 0)//有数据
                {
                    strMessage.Append("<a href='" + GetUrlByWarningType((typeId)) + "' id='" + GetHrefIdByWarningType((typeId)) + "' >");
                    strMessage.Append("<span style='line-height:150%;color:red;text-decoration: none;'>");
                    strMessage.Append("您有 <b>" + Rows.Length + "</b> 个<<" + GetNameByWarningType((typeId)) + ">>待查看");
                    strMessage.Append("</span></a><br>");
                }

            }
            //手动查看提醒，若没有提醒，则弹出说明信息。
            if (dt.Rows.Count == 0 || strMessage.Length <= 0)
            {
                strMessage.Append("<span style='line-height:150%;color:red;text-decoration: none;'>暂时没有提醒。</span><br>");
            }


            return strMessage.ToString();

        }

        /// <summary>
        /// 根据消息类型获得目标URL
        /// </summary>
        /// <param name="typeId"></param>
        /// <returns></returns>
        private string GetUrlByWarningType(int typeId)
        {
            string url = "";
            switch (typeId)
            {

                case 1:
                    //医院药品监控
                    url = "/Message/MessageListForType1.aspx";
                    break;
                case 2:
                    //企业药品监控
                    url = "/Message/MessageListForType2.aspx";
                    break;
                case 3:
                    //医院已提交采购单企业未确认
                    url = "/Message/MessageListForType3.aspx";
                    break;
                case 4:
                    //医院已提交退货单企业未确认
                    url = "../Message/MessageListForType4.aspx";
                    break;
                case 5:
                    //医院已提交回款单企业未确认
                    url = "Message/MessageListForType5.aspx";
                    break;
                case 6:
                    //企业已确认定单医院未入库
                    url = "../Message/MessageListForType6.aspx";
                    break;
                case 7:
                    //医院已入库未回款
                    url = "../Message/MessageListForType7.aspx";
                    break;
                case 8:
                    //医院已入库未回款
                    url = "../Message/MessageListForType8.aspx";
                    break;
                case 9:
                    //医院已入库未回款
                    url = "../Message/MessageListForType9.aspx";
                    break;
                case 10:
                    //医院已入库未回款
                    url = "../Message/MessageListForType10.aspx";
                    break;
                case 11:
                    //医院已入库未回款
                    url = "../Message/MessageListForType11.aspx";
                    break;
                case 12:
                    //医院已入库未回款
                    url = "../Message/MessageListForType12.aspx";
                    break;

                default:
                    url = "";
                    break;
            }

            return url;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="typeId"></param>
        /// <returns></returns>
        private string GetNameByWarningType(int typeId)
        {
            string name = "";
            switch (typeId)
            {
                case 1:
                    name = "医院药品监控";
                    break;
                case 2:
                    name = "企业药品监控";
                    break;
                case 3:
                    name = "医院已提交采购单企业未确认";
                    break;
                case 4:
                    name = "医院已提交退货单企业未确认";
                    break;
                case 5:
                    name = "医院已提交回款单企业未确认";
                    break;
                case 6:
                    name = "企业已确认定单医院未入库";
                    break;
                case 7:
                    name = "医院已入库未回款";
                    break;
                case 8:
                    name = "配送企业已确认采购单未发货";
                    break;
                case 9:
                    name = "配送企业已发货未开票";
                    break;
                case 10:
                    name = "配送企业接收未入库";
                    break;
                case 11:
                    name = "生产企业接收未响应";
                    break;
                case 12:
                    name = "生产企业响应未发货";
                    break;
                default:
                    name = "";
                    break;
            }

            return name;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="typeId"></param>
        /// <returns></returns>
        private string GetHrefIdByWarningType(int typeId)
        {
            string name = "";
            switch (typeId)
            {
                case 1:
                    name = "linkjdwtj";
                    break;
                case 2:
                    name = "linktjwqr";
                    break;
                case 3:
                    name = "linkqrwps";
                    break;
                case 4:
                    name = "linkpswys";
                    break;
                case 5:
                    name = "linkrkwkp";
                    break;
                case 6:
                    name = "linkkpwhk";
                    break;
                case 7:
                    name = "linkhkwqr";
                    break;
                case 8:
                    name = "link8";
                    break;
                case 9:
                    name = "link9";
                    break;
                case 10:
                    name = "link10";
                    break;
                case 11:
                    name = "link11";
                    break;
                case 12:
                    name = "link12";
                    break;
                default:
                    name = "";
                    break;
            }

            return name;
        }
    }
}
